cmake_minimum_required(VERSION 3.16)

project(ijkplayer)

set(CMAKE_INSTALL_PREFIX install)

add_subdirectory(libyuv)

# 设置 C++ 标准
#set(CMAKE_CXX_STANDARD 14)
set(C_STANDARD 99)

add_definitions(-D__LINUX__)
set(PLATFORM x64)
if (CMAKE_SYSTEM_PROCESSOR MATCHES "x86_64")
   message(STATUS "x86_64 architecture detected")
   set(CMAKE_BUILD_TYPE Debug)
elseif (CMAKE_SYSTEM_PROCESSOR MATCHES "arm")
   message(STATUS "ARM architecture detected")
   set(PLATFORM arm)
else()
   message(WARNING "Unknown architecture")
endif()

# 包含头文件目录
include_directories(
    ${PROJECT_SOURCE_DIR}
    ${PROJECT_SOURCE_DIR}/libyuv/include
    "${PROJECT_SOURCE_DIR}/../extra/ffmpeg"
)
link_directories("${PROJECT_SOURCE_DIR}/${PLATFORM}/install/lib")

# 源文件
file(GLOB_RECURSE IJKPLAYER_FILES ${PROJECT_SOURCE_DIR}/ijkplayer/*.c)
file(GLOB_RECURSE IJKSDL_FILES ${PROJECT_SOURCE_DIR}/ijksdl/*.c)
list(APPEND SRC_FILES ${IJKPLAYER_FILES} ${IJKSDL_FILES})
# 定义不需要包含的文件夹
set(EXCLUDE_DIRS
    "${PROJECT_SOURCE_DIR}/ijkplayer/android"
    "${PROJECT_SOURCE_DIR}/ijksdl/android"
)
# 过滤掉不需要的文件夹
foreach(EXCLUDED_DIR ${EXCLUDE_DIRS})
    list(FILTER SRC_FILES EXCLUDE REGEX "^${EXCLUDED_DIR}/.*")
endforeach()
message(STATUS "source: ${SRC_FILES}")

# 添加动态库
add_library(${PROJECT_NAME} SHARED ${SRC_FILES})

# 设置动态库链接
target_link_libraries(${PROJECT_NAME} PRIVATE yuv)

# 安装动态库和头文件
install(TARGETS ${PROJECT_NAME} LIBRARY DESTINATION lib)
#install(FILES ${PROJECT_SOURCE_DIR}/ijkplayer/ijkplayer.h DESTINATION include)
